<template>
  <div class="identificationmanagement">
    <div class="typetop">
      <el-button type="primary" @click="addidentfun((isSet = 0))">添加标识</el-button>
    </div>
    <div class="biaoshiList">
      <el-table :data="pageBsData" border style="width: 100%; margin-bottom: 20px">
        <el-table-column prop="id" label="ID"> </el-table-column>
        <el-table-column prop="name" label="标识名称"> </el-table-column>
        <el-table-column prop="createName" label="添加人"> </el-table-column>
        <el-table-column prop="updateTime" label="添加时间"> </el-table-column>
        <el-table-column prop="note" label="备注"> </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button @click="addidentfun(scope.row, (isSet = 1))" type="text" size="small">编辑</el-button>
            <el-button @click="deletepagebs(scope.row.id)" type="text" size="small">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        background
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        :page-size="formData.pageSize"
        :current-page="formData.pageNum"
        @current-change="SetPage"
        @size-change="handleSizeChange"
      ></el-pagination>
    </div>
    <!-- 添加类型弹窗 -->
    <AddIdentificaton ref="edit" :adDialogFormVisible="adDialogFormVisible" @editorList="editList"></AddIdentificaton>
  </div>
</template>
<script>
import AddIdentificaton from "./components/addIdentification";
import { getTypeList, deleteAppType } from "@/api/basisMG";
export default {
  components: {
    AddIdentificaton,
  },
  data() {
    return {
      title: "",
      adDialogFormVisible: false,
      pageBsData: [],
      formData: {
        type: 3,
        productType: "",
        pageNum: 1,
        pageSize: 10,
      },
      total: 0,
    };
  },
  methods: {
    // 分页
    SetPage(e) {
      this.formData.pageNum = e;
      this.getTypeList();
    },
    handleSizeChange (val) {
      this.formData.pageSize = val;
      this.getTypeList();
    },
    async getTypeList() {
      const res = await getTypeList(this.formData);
      if (res.code === '200') {
        this.pageBsData = res.data.content;
        this.total = res.data.total;
      } else {
        this.pageBsData = [];
      }
    },
    deletepagebs(id) {
      this.$confirm("确定要删除吗？删除后将无法恢复，请谨慎操作", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          const data = await deleteAppType({id:id});
          if (data.code != 200) return this.$message.error("操作失败请稍后重试");
          this.getTypeList();
          this.$message({
            type: "success",
            message: "删除成功!",
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    addidentfun(row) {
      const rowList = {};
      if (this.isSet == 0) {
        //点击添加
        rowList.isSet = 0;
      } else {
        //点击编辑
        rowList.name = row.name;
        rowList.note = row.note;
        rowList.id = row.id;
        rowList.isSet = 1;
      }
      this.$refs["edit"].showEdit(rowList);
    },
    editList(e) {
      this.getTypeList();
    }
  },
  created() {
    this.getTypeList();
  }
};
</script>
<style lang="scss">
.identificationmanagement {
  padding: 20px;
  .typetop {
    padding-bottom: 20px;
  }
}
</style>
